Skip to content

Declare createSynchronizedPrettier as only named export#12

Merged
fisker merged 5 commits into
prettier:mainfrom
colinrotherham:export-default
Jun 8, 2025
Merged

Declare createSynchronizedPrettier as only named export#12
fisker merged 5 commits into
prettier:mainfrom
colinrotherham:export-default

Conversation

@colinrotherham

@colinrotherham colinrotherham commented Jul 17, 2023

Copy link
Copy Markdown
Contributor

As discussed in alphagov/govuk-frontend#3971 (comment) @prettier/sync doesn't support named exports:

import { format } from '@prettier/sync'

This PR updates the type declarations to show that

I've also updated the tsconfig.json file so local test.js imports are checked too

Named exports not allowed

Comment thread test.js Outdated
fileURLToPath(fakePrettierUrl),
]) {
test(prettierEntry, async () => {
test(prettierEntry.toString(), async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler flagged this line because test() only accepts string not URL

@remcohaszing remcohaszing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you’re trying to do, but I’m not sure if there is a proper way to do this correctly.

Interestingly, this works, but it relies on errors in the local type definitions:

// @ts-expect-error
declare const synchronizedPrettier: SynchronizedPrettier;

// @ts-expect-error
declare namespace synchronizedPrettier {
  function createSynchronizedPrettier(options: {
    prettierEntry: string | URL;
  }): SynchronizedPrettier
}

Comment thread index.d.cts Outdated
Comment thread tsconfig.json Outdated
@colinrotherham colinrotherham marked this pull request as draft July 17, 2023 16:18
@colinrotherham colinrotherham marked this pull request as ready for review July 17, 2023 19:53
Comment thread test.js Outdated
Updates types to show that `createSynchronizedPrettier` is the only ESM named export to ensure TypeScript throws errors for invalid named exports such as:

```
import { format } from '@prettier/sync'
```
@fisker fisker merged commit 9a2de4d into prettier:main Jun 8, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants